% Copyright 2018 Google LLC
%
% Use of this source code is governed by an MIT-style
% license that can be found in the LICENSE file or at
% https://opensource.org/licenses/MIT.

\documentclass[eprint.tex]{subfiles}
\begin{document}
\begin{tikzpicture}
  [line width=0.6,
   box/.style = {
     draw, rectangle, rounded corners
   },
   wire/.style = {
     ->,rounded corners=1.5pt
   },
   minimum size=0.5cm,
   x=1.5cm, y=1.5cm
  ]

  %Draw nodes
  \node[rectangle] at (0,0) (PL) {$P_L$};
  \node[rectangle] at (2,0) (PR) {$P_R$};
  \node[cbox] at (1,-1) (H0) {$H_{K_H}$};
  \node[ADD] at (PR |- H0) (plus) {};
  \node[cbox] at (2,-2) (E) {$E_{K_E}$};
  \node[rectangle] at (-1,-2.5) (T) {$T$};
  \node[cbox] at (1,-3) (PRF) {$S_{K_S}$};
  \node[XOR] at (PL |- PRF) (fxor) {};
  \node[cbox] at (1,-4) (H1) {$H_{K_H}$};
  \node[SUB] at (PR |- H1) (minus) {};
  \node[rectangle] at (0,-5) (CL) {$C_L$};
  \node[rectangle] at (minus |- CL) (CR) {$C_R$};


  \draw[wire] (PR) -- (plus);
  \draw[wire] (PL) -- (fxor);
  \draw[wire] ([yshift=-1ex] CL |- H0) -- ([yshift=-1ex] H0.west);
  \draw[wire] (H0) -- (plus);
  \draw[wire] (plus) -- node[right] {$P_M$} (E);
  \draw[wire] (PR |- PRF) -- (PRF);
  \draw[wire] (PRF) -- (fxor);
  \draw[wire] (E) -- node[right] {$C_M$} (minus);
  \draw[wire] (T) -- ++(0.5, 0) |- ([yshift=+1ex] H0.west);
  \draw[wire] (T) -- ++(0.5, 0) |- ([yshift=+1ex] H1.west);
  \draw[wire] (fxor) -- (CL);
  \draw[wire] ([yshift=-1ex] CL |- H1) -- ([yshift=-1ex] H1.west);
  \draw[wire] (H1) -- (minus);
  \draw[wire] (minus) -- (CR);
\end{tikzpicture}
\end{document}
